var vue = new Vue({
    el: '#app',
    data() {
        return {
            showScreen: false,
            loading: false,
            finished: false,
            list: [], // 列表
            is_standard: 1, //是否为待整改  待整改1 已整改2
            selceList: [], // 筛选条件
            riskIndex: '0', // 风险等级选中
            riskId: '', // 筛选 风险等级
            timeIndex: '0', // 整改时限选中
            timeId: '', // 筛选整改时限
            industryIndex: '0', // 行业选中
            industryId: '', // 筛选行业
            communityIndex: '0', // 社区选中
            communityId: '', // 筛选社区
            safetyIndex: '0', // 安全员选中
            safetyId: "", // 筛选安全员
            businessList: [], // 主营业务列表
            businessId: '', // 主营业务
            businessIndex: '0', // 主营业务选中
            businessShow: false,
            searchValue: '', //搜索关键字
            isSearching: false, //是否正在搜索
            loadShow: false,
            page: 1,
            backTop: false,
            id: '', //网格id
            yearS: '', //query
            season: '', //query
            year: '', //当前年份
            quarter: '', //当前年份
            is_quarter: '', // 筛选项
            total: 0, //隐患总数
        }
    },
    created() {
        this.id = getRequest().id
        this.is_standard = getRequest().tabIndex
        this.searchValue = getRequest().keywords || ''
        this.yearS = getRequest().yearS || ''
        this.season = getRequest().season || ''
        this.getList();
        this.getTime()
        setTimeout(() => {
            this.loadShow = false;
        }, 10)
    },
    mounted() {
        $(window).scroll(() => {
            var topp = $(document).scrollTop();
            if (topp > 200) {
                this.backTop = true
            } else {
                this.backTop = false
            }
        })

        window.addEventListener("visibilitychange", () => {
            if (document.hidden) {

            } else {
                this.id = getRequest().id
                this.is_standard = getRequest().tabIndex
                this.searchValue = getRequest().keywords || ''
                this.yearS = getRequest().yearS || ''
                this.season = getRequest().season || ''
                this.getList();
                this.getTime()
                setTimeout(() => {
                    this.loadShow = false;
                }, 10)
            }
        })
    },
    methods: {
        // 获取时间
        getTime() {
            let time = new Date()
            this.year = time.getFullYear()
            let currentMonth = time.getMonth() + 1;
            if (currentMonth >= 1 && currentMonth <= 3) {
                this.quarter = 1;
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                this.quarter = 2;
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                this.quarter = 3;
            } else {
                this.quarter = 4;
            }
        },
        //获取列表数据
        getList() {
            ajax({
                url: formal + '/place-check/get-grids-place?grids_id=' + this.id + '&page=' + this.page + '&keywords=' + this.searchValue + '&is_standard=' + this.is_standard + '&is_quarter=' + this.is_quarter + '&year=' + this.yearS + '&season=' + this.season,
                type: 'GET',
                success: (res1) => {
                    this.total = res1.data.total
                    let res = res1.data.list
                    this.isSearching = false
                    // 数据全部加载完成
                    if (res.length == 0) {
                        this.finished = true;
                        return;
                    }
                    this.list.push(...res)
                    this.page++;
                    // 加载状态结束
                    this.loading = false;
                }
            })
        },
        // 去详情
        gorRecordDetails(uuid) {
            location.href = "../recordDetails.html?id=" + uuid + "&status=" + 1 + "&is_standard=" + this.is_standard + "&type=2";
            // sessionStorage.setItem('record',uuid);
        },
        // 返回首页
        goHome() {
            location.href = "./index.html?from=1"
        },
        // tag筛选
        changeQuarter(val) {
            this.is_quarter = val
            this.list = []
            this.page = 1
            this.getList()
        },
        // 获取筛选
        getSelece() {

        },
        // 选择
        select(index, id, type, children) {

        },
        // 文字搜索
        charactersSearch() {
            if (this.searchValue == '') {
                this.search()
            }
        },
        search() {
            if (this.isSearching) {
                return
            }
            this.isSearching = true
            this.list = []
            this.page = 1
            this.getList()
        },
        // 重置
        resetting() {

        },
        // 关闭筛选
        closeSelect() {

        },
        // 确定
        determine() {

        },
        onLoad() {
            this.getList()
        },
        // 点击返回顶部
        topclick() {
            console.log(1111);
            scrollTo({
                top: 0,
                behavior: "smooth",
            });
        },
    },

})